//
// Created by apple on 2023/2/20.
//

#ifndef TREEKV_TREEKV_DB_H
#define TREEKV_TREEKV_DB_H

#include "../core/db.h"
#include <iostream>
#include <string>
#include <mutex>
#include "../core/properties.h"

#include "../../../src/db/server.h"

using std::cout;
using std::endl;

namespace ycsbc {

    using namespace std;

    class OrderkvDB : public DB {

    private:
//        std::mutex mutex_;
        db::Server *server = new db::Server;

    public:

        int Read(const std::string &table, const std::string &key, const std::vector<std::string> *fields,
                 std::vector<KVPair> &result) {

//            std::lock_guard<std::mutex> lock(mutex_);
//            printf("read\n");
            server->query(key);

            return 0;

        }

        int Scan(const std::string &table, const std::string &key, const std::string &max_key,
                 int len, const std::vector<std::string> *fields,
                 std::vector<std::vector<KVPair>> &result) {
//            std::lock_guard<std::mutex> lock(mutex_);

//            printf("scan\n");

//            vector<string> keys;
//            vector<string> values;
            server->range_query(key, max_key, len);
//            server.getRange(key, len, keys, values);

            return 0;

        }

        int Insert(const std::string &table, const std::string &key, std::vector<KVPair> &values) {
            for (const auto &item: values) {
                server->put(key, item.second);
            }
            return 0;

        }

        int Update(const std::string &table, const std::string &key, std::vector<KVPair> &values) {
            for (const auto &item: values) {
                server->put(key, item.second);
            }
            return 0;
        }

        int Delete(const std::string &table, const std::string &key) {
//            printf("delete\n");
//            server.del(key);
            return 0;
        }

        ~OrderkvDB() override {
            delete server;
        }
    };

} // ycsbc


#endif //TREEKV_TREEKV_DB_H
